package day11.homework;

import java.util.*;

public class DateTest {
	public static void main(String args[]) {

		Scanner sca = new Scanner(System.in);
		System.out.println("请输入你要打印的日期：格式为2008-8-8:");
		String r = sca.next();
		String formatReg = "^\\d{4}-([1-9]|10|11|12)-([0-9]|1[0-9]|2[0-9]|30|31)$";
		if (!r.matches(formatReg)) {
			System.out.println("日期格式不正确");
			return;
		}
		String[] s = new String[3];
		s = r.split("-");
		int y = Integer.parseInt(s[0]);
		int m = Integer.parseInt(s[1]);
		int d = Integer.parseInt(s[2]);
		if (y % 4 == 0 && m == 2 && d > 29) {
			System.out.println("瑞年二月份只有29天！");
			return;
		} else if (!(y % 4 == 0) && m == 2 && d > 28) {
			System.out.println("平年的二月份只有28天");
			return;
		} else if (m == 4 || m == 6 || m == 9 || m == 11 || (d > 30 && d < 0)) {
			System.out.println("小月份只有30天!");
			return;
		}
		Calendar c = Calendar.getInstance();
		c.set(y, m - 1, d);
		Date d1 = c.getTime();
		System.out.println(d1);
	}
}
